$(document).ready(function () {

    // 入库
    $("#deliveryInputBtn").click(function () {
        $.ajax({
            url: "/api/delivery/" + $("#deliveryInput").val(),
            type: 'POST',
            data: {},
            complete: function (result) {
                console.log(result);
            }
        });
    });

    // 扫码出库
    $("#deliveryOutputBtn").click(function () {
        $.ajax({
            url: "/api/delivery/" + $("#deliveryOutput").val() + "/state",
            type: 'PUT',
            data: { "state": "OUTBASE" },
            complete: function (result) {
                console.log(result);                
            }
        });
    });

    // 按键出库
    $(".btn-out").click(function () {
        $.ajax({
            url: "/api/delivery/" + $(this).parents(".table-body").find(".delivery-name").text() + "/state",
            type: 'PUT',
            data: { "state": "OUTBASE" },
            complete: function (result) {
                location.reload();                
            }
        });
    });

    // 退回
    $(".btn-return").click(function () {
        $.ajax({
            url: "/api/delivery/" + $(this).parents(".table-body").find(".delivery-name").text() + "/state",
            type: 'PUT',
            data: { "state": "RETURN" },
            complete: function (result) {
                location.reload();
            }
        });
    });

    // 删除
    $(".btn-delete").click(function () {
        $.ajax({
            url: "/api/delivery/" + $(this).parents(".table-body").find(".delivery-name").text(),
            type: 'DELETE',
            complete: function (result) {
                location.reload();
            }
        });
    });

    // 修改备注
    $(".btn-update-info").click(function () {
        $.ajax({
            url: "/api/delivery/" + $(this).parents(".table-body").find(".delivery-name").text() + "/info",
            type: 'PUT',
            data: { "info": $(this).parents(".table-body").find("form .input-info").val() },
            complete: function (result) {
                // location.reload();
                console.log(result);
            }
        });
    });

    window.onload = function () {
        document.getElementById("deliveryInput").focus();
        
    }
});
